<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/back.css" />
<script language="javascript" src="${pageContext.request.contextPath}/js/back_test.js"></script>
<script type="text/javascript">
function chagngClass(classId){
	
	document.getElementById("itemId").length = 1;
	<c:forEach items="${list}" var="item">
		if (${item.parentId} == classId){
			var option = new Option("${item.itemName}","${item.itemId}");
			document.getElementById("itemId").add(option);
		}
	</c:forEach>
}
function mod(){
	document.getElementById("noPath").value="";
	
}
function CheckForm(){
	var pricevalue=Trim(document.form1.price.value);
	var numvalue=Trim(document.form1.num.value);
	
	if(document.form1.classId.value == ""){
		alert("商品品牌不能为空");
		document.form1.classId.focus();
		return false;
	}	
	else if(document.form1.itemId.value == ""){
		alert("商品类别不能为空");
		document.form1.itemId.focus();
		return false;
	}
	else if(Trim(document.form1.goodsName.value) == ""){
		alert("商品名称不能为空");
		document.form1.goodsName.focus();
		return false;
	}else if(pricevalue.length ==0){
			alert("商品价格不能空");
			document.form1.price.focus();
			return false;
	}else if(isNaN(pricevalue)){
			alert("商品价格必须为数字");
			document.form1.price.focus();
			return false;
	}else if(pricevalue <0){
			alert("商品价格不能为负数");
			document.form1.price.focus();
		return false;
	}else if(numvalue.length ==0){
			alert("商品数量不能空");
			document.form1.num.focus();
			return false;
	}else if(isNaN(numvalue)){
			alert("商品数量必须为数字");
			document.form1.num.focus();
		return false;
	}else if(numvalue <0){
			alert("商品数量不能为负数");
			document.form1.num.focus();
		return false;
	}else if(Trim(document.form1.direction.value) == ""){
		aler("商品描述不能为空");
		document.form1.direction.focus();
		return false;
	}
	return true;
}

</script>
<form action="${pageContext.request.contextPath}/GoodsServlet?service=addgoods" method="post" name="form1" enctype="multipart/form-data" onsubmit="return CheckForm();">
	<table align="center" width="600px" border="1" cellspacing="0" bordercolordark="#FFFFFF" bordercolorlight="#0066cc" style="font-size: 9pt;">
		<tr>
			<td>
				<table align="center">
					<tr>
						<td height="40px;">请选择商品的品牌：
						</td>
						<td>
							<select id="classId" name="classId" onchange="chagngClass(this.value);">
								<option value="">
												====请选择类别====
								</option>
								<c:forEach items="${biglist}" var="class">
									<option value="${class.classId}">${class.className}</option>
								</c:forEach>
							</select><span style="color: red;">*</span>			
						</td>
					</tr>
					<tr>
						<td height="40px;">请选择商品的类别：
						</td>
						<td>
							<select id="itemId" name="itemId">
								<option value="">
												====请选择类别====
								</option>
								<c:forEach items="${list}" var="itemBean">
									<option value="${item.itemId}">${item.itemName}</option>
								</c:forEach>
							</select><span style="color: red;">*</span>
						</td>
					</tr>
					<tr>
						<td height="40px;">
							请输入商品的名称：
						</td>
						<td>
							<input type="text" id="goodsName" name="goodsName"><span style="color: red;">*</span>
						</td>
					</tr>
					<tr>
						<td height="40px;">请输入商品的价格：
						</td>
						<td>
							<input type="text" id="price" name="price"><span style="color: red;">*</span>
						</td>
					</tr>
					<tr>
						<td height="40px;">请输入商品的数量：
						</td>
						<td>
							<input type="text" id="num" name="num"><span style="color: red;">*</span>
						</td>
					</tr>
					<tr>
						<td height="60px;">
							<span>请输入对商品的描述：</span>
						</td>
						<td>
							<textarea rows="4" id="direction" name="direction"></textarea><span style="color: red;">*</span>	
						</td>
					</tr>
					<tr>
						<td height="40px;">
							请选择商品的图片：
						</td>
						<td>
							<input type="file" id="picPath" name="picPath" onchange="mod();">
							<input type="hidden" id="noPath" name="moren" value="noPic.jpg">
						</td>
					</tr>
					<tr align="center">
						<td height="40px;">
							<input type="submit" value="提交">
						</td>
						<td>
							<input type="reset" value="重置">
						</td>
					</tr>
			</table>
			</td>
		<tr>
	</table>
</form>